<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>计时器</title>
	</head>
	<body>
		<!-- <script type="text/javascript">
			window.onload=function(){
				sto=window.setTimeout(function(){
					alert("123");
				},5000)
				set=setInterval(function(){
					alert("123");
				},1000)
				var bu=document.getElementById("bu")
				bu.onclick=function(){
					clearTimeout(sto);
					clearInterval(set);
					if(bu.innerHTML="停止"){
						bu.innerHTML="启动";
					}
					else{
						bu.innerHTML="停止";
					}
					
					
				}
				
			}
		
		</script>
		<button type="button" id="bu">停止</button> -->
		<p id="p1"></p>
		<script type="text/javascript">
			function pd(a){
				if(a<=9){
					return "0"+a;
				}
				else{return a;}
				
			}
			setInterval(function(){
				var date=new Date();
				var y=date.getFullYear();
				var m=pd(date.getMonth()+1);
				var d=pd(date.getDate());
				var h=pd(date.getHours());
				var f=pd(date.getMinutes());
				var s=pd(date.getSeconds());
				//法一：以秒为例/调用函数连续判断
				
				var str=y+"-"+m+"-"+d+" "+h+":"+f+":"+s;
				document.getElementById("p1").innerText=str;
				
			})
		</script>
	</body>
</html>
